//package com.match.competition_role.controller;
//
//
//import com.google.code.kaptcha.Producer;
//import com.match.commonutils.Const;
//import com.match.commonutils.Result;
//
//import com.match.competition_role.utils.RedisUtil;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.util.StringUtils;
//import org.springframework.web.bind.annotation.*;
//import sun.misc.BASE64Encoder;
//
//import javax.imageio.ImageIO;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.awt.image.BufferedImage;
//import java.io.ByteArrayOutputStream;
//import java.util.UUID;
//
//@Api(tags = {"Google-kaptcha验证码"})
//@RestController
//@RequestMapping("/api/competition_role/kaptcha")
//public class KaptchaController {
//    @Autowired
//    Producer producer;
//    @Autowired
//    RedisUtil redisUtil;
//
//    @ApiOperation(value = "生成验证码")
//    @GetMapping("/defaultKaptcha")
//    public Result defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
//            throws Exception {
//            String key= UUID.randomUUID().toString();
//            String code =producer.createText();
//
//            BufferedImage image=producer.createImage(code);
//            ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
//            ImageIO.write(image,"jpg",outputStream);
//
//            BASE64Encoder encoder=new BASE64Encoder();
//            String str="data:image/jpeg;base64,";
//
//            String base64Img=str+encoder.encode(outputStream.toByteArray());
//            redisUtil.hset(Const.CAPTCHA_KEY,key,code,120);
//            return Result.ok().data("token",key).data("captchaImg",base64Img);
//    }
//
//    @ApiOperation(value = "校对验证码")
//    @PostMapping("/checkVerificationCode")
//    public Result checkVerificationCode(@RequestParam(value = "verificationCode") String verificationCode, HttpServletRequest httpServletRequest) {
//        String verificationCodeIn = (String) httpServletRequest.getSession().getAttribute("verificationCode");
//        httpServletRequest.getSession().removeAttribute("verificationCode");
//        if (StringUtils.isEmpty(verificationCodeIn) || !verificationCodeIn.equals(verificationCode)) {
//            return Result.error().message("验证码错误，或已失效");
//        }
//        return Result.ok();
//    }
//}
